package tests;

import static org.junit.Assert.fail;

import java.util.ArrayList;
import java.util.HashSet;

import org.junit.Assert;
import org.junit.Test;

import base.Event;
import base.Tag;

public class EventTest {

    @Test
    public void testEvent() {
        Assert.assertNotNull(new Event());
    }

    @Test
    public void testEventString() {
        Assert.assertNotNull(new Event("My Event"));
    }

    @Test
    public void testEventStringSetOfTag() {
        Assert.assertNotNull(new Event("My Event", new HashSet<Integer>()));
    }

    @Test
    public void testEventIntStringSetOfTag() {
        try {
            Event event = new Event(-1, "Tag invalide", new HashSet<Integer>());

            System.out.println(event);
            fail("Une exception aurait dû être levée");
        } catch (IllegalArgumentException e) {
            Assert.assertEquals(e.getMessage(), "Invalid Event ID");
        }
    }

    @Test
    public void testSetName() {
        Event event = new Event("My tag");
        event.setName("My new tag");
        Assert.assertEquals("My new tag", event.getName());
    }

    @Test
    public void testGetName() {
        Event event = new Event("My tag");
        Assert.assertEquals("My tag", event.getName());
    }

    @Test
    public void testToString() {
        Event event = new Event(2, "My tag", new HashSet<Integer>());
        Assert.assertEquals("Event 2 (My tag)", event.toString());
    }

    @Test
    public void testEqualsObject() {
        Event event1 = new Event(3, "Event", new HashSet<Integer>());
        Event event2 = new Event(4, "Event", new HashSet<Integer>());

        Assert.assertFalse(event1.equals(event2));

        Event event3 = new Event(3, "Event", new HashSet<Integer>());
        Assert.assertTrue(event1.equals(event3));
    }

    @Test
    public void testAddTag() {
        Event event = new Event("My Event");
        event.add(new Tag("My tag"));
        Assert.assertEquals(event.getTags().size(), 1);
    }

    @Test
    public void testRemoveTag() {
        HashSet<Integer> tags = new HashSet<Integer>();
        tags.add(4);
        Event event = new Event(3, "My Event", tags);
        event.remove(new Tag(4, "My Tag"));
        Assert.assertEquals(event.getTags().size(), 0);
    }

    @Test
    public void testGetTags() {
        Tag mytag = new Tag("My Tag");
        HashSet<Integer> tags = new HashSet<Integer>();
        tags.add(9);
        Event event = new Event(3, "My Event", tags);
        event.remove(mytag);
        Assert.assertEquals(event.getTags(), tags);
    }

    @Test
    public void testSetTags() {
        Event event = new Event("My Event");
        event.add(new Tag("My tag"));
        Assert.assertEquals(event.getTags().size(), 1);

        Tag mytag = new Tag("My Tag");
        ArrayList<Integer> tags = new ArrayList<Integer>();
        tags.add(mytag.getID());

        Assert.assertEquals(event.getTags(), tags);
    }

    @Test
    public void testContains() {
        Event event = new Event("My Event");
        Assert.assertFalse(event.contains(new Tag("")));
        event.add(new Tag("My tag"));
        Assert.assertTrue(event.contains(new Tag("")));
    }

    @Test
    public void testIsEmpty() {
        Event event = new Event("My Event");
        Assert.assertTrue(event.isEmpty());
        event.add(new Tag("My tag"));
        Assert.assertFalse(event.isEmpty());
    }

    @Test
    public void testClear() {
        Event event = new Event("My Event");
        event.add(new Tag("My tag"));
        Assert.assertEquals(event.getTags().size(), 1);

        event.clear();
        Assert.assertEquals(event.getTags().size(), 0);
    }

    @Test
    public void testGetID() {
        Event event = new Event(1, "My event", new HashSet<Integer>());
        Assert.assertEquals(event.getID(), 1);
    }
}
